 <!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,fancybox,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>
<body>

<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                    <div class="form-group">
                        <label class="control-label col-sm-1">国家:</label>
                        <div class="col-sm-2">
                            <select  name="productCountry" id="productCountry" class="form-control">
                                <option value="">全部分类</option>
                                <option value="CA">CA</option>
                                <option value="DE">DE</option>
                                <option value="ES">ES</option>
                                <option value="EU">EU</option>
                                <option value="FR">FR</option>
                                <option value="IT">IT</option>
                                <option value="JP">JP</option>
                                <option value="UK">UK</option>
                                <option value="US">US</option>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">商品属性:</label>
                        <div class="col-sm-2">
                            <select  name="productPropertyId" id="productPropertyId" class="form-control">
                                <option value="">全部分类</option>
                                <%for(var dict in property){%>
                                <option value="${dict.detailCode}">${dict.detailName}</option>
                                <%}%>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">SKU:</label>
                        <div class="col-sm-2">
                            <input type="text" id="productSku" name="productSku" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">商品名称:</label>
                        <div class="col-sm-2">
                            <input type="text" id="productName" name="productName" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-1">大类:</label>
                        <div class="col-sm-2">
                            <select id="productBigClassId" name="productBigClassId"  class="form-control">
                                <option value="">全部分类</option>
                                <%for(var category in category){%>
                                <option value="${category.id}"  >${category.categoryName}</option>
                                <%}%>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">中类:</label>
                        <div class="col-sm-2">
                            <select id="productMidClassId" name="productMidClassId" class="form-control">
                                <option value="">全部分类</option>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">小类:</label>
                        <div class="col-sm-2">
                            <select id="productClassId" name="productClassId" class="form-control">
                                <option value="">全部分类</option>
                            </select>
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
        </div>
        <!-- END 右侧数据 -->
    </div>
</div>
    <form>
        <div id="toolbar" class="btn-group">
            <button  class="add-btn layui-btn layui-btn-normal layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
                <i class="fa fa-plus" aria-hidden="true"></i> 新增商品信息
            </button>
            <button  class="layui-btn layui-btn-sm import-btn" style="margin-top: -6px;margin-left: -4px" id="import-btn"  name="import-btn">
                <i class="layui-icon"></i>
                批量修改商品信息
            </button>
            <button  class="layui-btn layui-btn-sm import-add-btn" style="margin-top: -6px;margin-left: -4px" id="import-add-btn"  name="import-add-btn">
                <i class="layui-icon"></i>
                批量新增商品信息
            </button>
            <button  class="layui-btn layui-btn-sm " style="margin-top: -6px;margin-left: -4px"  >
                <i class="fa fa-download"></i><a href="/excel/商品模板.xlsx" style="color: white" download>模板下载</a>
            </button>

            <button  class="export-btn layui-btn  layui-btn-sm layui-btn-warm" style="margin-top: -6px;margin-left: -4px">
                <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
            </button>
        </div>
    </form>
<!-- START 数据表格 -->
<!-- START 数据表格 -->
    <div class="wrapper wrapper-content">
        <table id="productTable"
               data-toolbar="#toolbar"
               data-pagination="true"
               data-resizable="true"
               data-side-pagination="server"
               data-url="/sea/product/product/findByCnd.do"
               data-page-size="15"
               class="table table-striped table-hover">
        </table>
    </div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload,imgbox,layui'}){}%>
<script>
    var $productTable = $('#productTable');

    $(function () {
        $('.fancybox').fancybox({
            openEffect: 'none',
            closeEffect: 'none'
        });
        //新增
        $('.add-btn').on('click',function(){//新增
            layer.open({
                title: false,
                closeBtn: 0,
                type: 2,
                area: ['100%','100%'],
                skin: 'layer-ext-espresso',
                content: ['/sea/product/product/addPage.do', 'yes']
            });
        });
        // START 表格配置
        $productTable.bootstrapTable({
            pageSize:10,
            columns: [
               
                {
                    title: 'SKU',
                    field: 'productSku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '商品名称',
                    field: 'productName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '颜色',
                    field: 'productColorName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '大类名称',
                    field: 'productBigClassName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '中类名称',
                    field: 'productMidClassName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '小类名称',
                    field: 'productClassName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '尺码',
                    field: 'productSizeName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '尺寸(CM)',
                    field: 'productCm',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '尺寸(Inch)',
                    field: 'productInch',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '毛重',
                    field: 'productGrossWeight',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '净重',
                    field: 'productWeight',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '装箱数量',
                    field: 'productPackageNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '内含件数',
                    field: 'productContainCount',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '单位',
                    field: 'productUnit',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '修改时间',
                    field: 'modifyTime',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null != v && v.length>10) {
                            return v.substr(0, 10);
                        }else{
                            return v;
                        }
                    }
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                $('.edit-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        content: ['/sea/product/product/editPage.do?id='+id, 'yes']
                    });
                });

                //删除数据字典详情信息
                $('.del-btn').on('click',function(){
                    var delid = $(this).attr('data-val'),delname = $(this).attr('data-val-name');
                    //删除提示
                    layer.confirm('确定要删除当前数据？<br>['+delname+']', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/product/product/delete.do',{id: delid},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $productTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });
            }
        });

        // 条件查询
        $('.search-btn').on('click',function () {
            $productTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/product/product/findByCnd.do?'+$('#search-form').serialize() });
        });

    });

    // 操作菜单
    function optFormatter(value,row){
        var content = '<button class="edit-btn btn btn-xs btn-info" data-val="'+row.id+'" title="修改"><i class="fa fa-edit"></i> 修改</button>';
        content += '&nbsp;<a class="del-btn btn btn-xs btn-danger" data-val-name="'+row.productName+'" data-val="'+row.id+'" title="删除"><i class="fa fa-trash-o"></i> 删除 </a>';
        return content;
    }
    $(".export-btn").click(function () {
        window.location.href='/sea/product/product/export.do?'+$('#search-form').serialize();
    });


    $("#productBigClassId").change(function () {
        var parentId=$("#productBigClassId").val();
        getCategory(parentId,1);
    });
    $("#productMidClassId").change(function () {
        var parentId=$("#productMidClassId").val();
        getCategory(parentId,2);
    });

    function getCategory(parentId,type) {
        $.ajax({
            url:'/sea/product/category/findByParentId',
            data:{
                id:parentId
            },
            type:'post',
            success:function (data) {
                var list=data;
                if(list.length>0){
                    var category='<option value="">全部分类</option>';
                    for(var i=0;i<list.length;i++){
                        category+='<option value="'+list[i].id+'">'+list[i].categoryName+'</option>';
                    }
                    if(type=='1') {
                        $("#productMidClassId").html(category);
                    }
                    if(type=='2'){
                        $("#productClassId").html(category);
                    }
                }
            }
        });
    }


    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-btn', //绑定元素,
            accept:'file',
            url: '/sea/product/product/import/', //上传接口
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $productTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-add-btn', //绑定元素,
            accept:'file',
            url: '/sea/product/product/importAdd/', //上传接口
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                            layer.closeAll();
                            $productTable.bootstrapTable('refresh');
                        }});
                }else{
                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                            layer.closeAll();
                            $productTable.bootstrapTable('refresh');
                        }});

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });


</script>
</body>
</html>